package cn.iocoder.yudao.module.iot.mq;

import cn.iocoder.yudao.module.iot.enums.Channel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
public class Consumer {

    @Autowired
    private StringRedisTemplate redis;

    private ListOperations<String, String> listRedis;

    @PostConstruct
    private void init(){
        listRedis = redis.opsForList();
    }

    public void receive(){
        while (true){
            String message = listRedis.rightPop(Channel.UPLOAD_DEVICE_STATUS_CHANNEL);
            if(message == null || message.isEmpty()){
                System.out.println("消息队列为空");
                break;
            }
            System.out.println("message: " + message);
        }
    }

}